﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;


using MINERP.DAL;
using MINERP.DAL.CustomerManage;

namespace MINERP.BLL.CustomerManage
{
    public class TalkRecordsManageBLL
    {
        #region //private fields

        private List<Tb_TalkRecords> _collection = null;

        #endregion

        #region //Get Methods

        /// <summary>
        /// 得到同商户沟通的内容
        /// </summary>
        /// <param name="orderbagid"></param>
        /// <returns></returns>
        public List<TalkRecordEntity> GetTalkRecordByOrderBag(int orderbagid)
        {
            _collection = TalkRecordDAL.GetTalkRecordByBagID(orderbagid);

            List<TalkRecordEntity> list = new List<TalkRecordEntity>();

            foreach (Tb_TalkRecords record in _collection)
            {
                list.Add(new TalkRecordEntity(record));
            }

            return list;
        }

        #endregion

        #region //Add Methods

        public void AddOneRecord(int userid, string content, OrderBagEntity entity)
        {
            Tb_TalkRecords obj = new Tb_TalkRecords();

            obj.users = UserDAL.GetUserByID(userid);
            obj.Context = content;
            //obj.Tb_OrderBag = UserDAL.GetOrderByOrderId(entity.OrderBagID);
            obj.CreateTime = DateTime.Now;

            TalkRecordDAL.Save();
        }

        #endregion

    }


    #region //entity class

    public class TalkRecordEntity
    {
        private Tb_TalkRecords _obj = null;

        public bool IsDirty = true;

        #region //constructor

        public TalkRecordEntity()
        { 
        
        }

        public TalkRecordEntity(Tb_TalkRecords obj)
        {
            this._obj = obj;
        }

        #endregion


        #region //Public Proprities

        public int Id
        {
            get
            {
                return this._obj.Id;
            }
        }

        public DateTime CreateTime
        {
            get
            {
                return this._obj.CreateTime;
            }
        }

        public string bagName
        {
            get
            {
                //return this._obj.Tb_OrderBag.BagName;
                return "";
            }
        }

        public int bagID
        {
            get
            {
                //return this._obj.Tb_OrderBag.OrderBagId;
                return 0;
            }
        }

        public string UserName
        {
            get
            {
                return this._obj.users.UserName;
            }
        }

        public string Context
        {
            get
            {
                return this._obj.Context;
            }
            set
            {
                if (this._obj.Context != value)
                {
                    this.IsDirty = true;
                    this._obj.Context = value;
                }
            }
        }

        #endregion
    }

    #endregion
}
